# for hubert-large model (iter3)
exp_dir=$1
data_dir=$2
split=$3
all_data=( ${split} )

exp_name=$4
extract_layer=$5        # which layer to extract hiddens features
feat=${exp_name}_extract_layer_${extract_layer}
feat_dir=${exp_dir}/feature/${feat}
nj=$6
num_gpu=$7
hubert_ckpt=$8
echo "extract_hubert_feature.sh 打印各个变量:"
echo "exp_dir:"$exp_dir
echo "data_dir:"$data_dir
echo "split:"$split
echo "all_data:"${all_data[@]}
echo "exp_name:"$exp_name
echo "extract_layer:"$extract_layer
echo "feat:"$feat
echo "feat_dir:"$feat_dir
echo "nj:"$nj
echo "num_gpu:"$num_gpu
echo "hubert_ckpt:"$hubert_ckpt
echo "extract_hubert_feature.sh 打印各个变量结束"

echo "Compute Hubert (iter2) features started @ `date`"
start=$(date +%s)

for set in "${all_data[@]}"; do
    echo "drop feat: $set"
    for ((i = 0; i < $nj; ++i)); do
    {
        result=$((i % num_gpu))
        export CUDA_VISIBLE_DEVICES=$result
        # set 是tsv文件的文件名字； max_chunk单位是采样点是对于长音频，每次提取多少采样点，然后在维度拼接
        python tools/dump_hubert_feature.py   \
            ${data_dir} ${set}                        \
            $hubert_ckpt   \
            ${extract_layer} ${nj} $i ${feat_dir}/${set}  \
            --max_chunk 16000000
    }   &
    done
    wait
done
echo "Compute Hubert (iter2) features Done @ `date`"
end=$(date +%s)
echo "Execution time: $((end - start)) seconds"